﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;

namespace Appliaction.AppServices.DB
{
    public class Db_ProductService : IDb_ProductService
    {
        private readonly IDb_ProductRepository db_ProductRepository;
        private readonly IMapper mapper;

        public Db_ProductService(IDb_ProductRepository db_ProductRepository,IMapper mapper)
        {
            this.db_ProductRepository = db_ProductRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 验证序号是不是唯一
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="proId"></param>
        /// <returns></returns>
        public bool CheckSortUnique(int sort, int proId)
        {
            return db_ProductRepository.CheckSortUnique(sort, proId);
        }

        /// <summary>
        /// 根据编号查询对应产品信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<Db_Product> GetDb_ProductByCode(string code)
        {
            return db_ProductRepository.GetDb_ProductByCode(code);
        }

        /// <summary>
        /// 分页条件查询产品信息
        /// </summary>
        /// <param name="proName"></param>
        /// <param name="typeCode"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<Db_Product> Get_Products(string proName, string typeCode, int currentPage, int pageSize)
        {
            return db_ProductRepository.Get_Products(proName,typeCode,currentPage,pageSize);
        }
        /// <summary>
        /// 查询产品信息--其他入库单
        /// </summary>
        /// <param name="procode"></param>
        /// <param name="Pro_type_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Db_Product> Get_Products_Other(string procode, string Measure_id, int currentPage, int pageSize)
        {
            return db_ProductRepository.Get_Products_Other(procode, Measure_id, currentPage,pageSize);
        }

        /// <summary>
        /// 查询产品信息-其他入库单-总数
        /// </summary>
        /// <param name="procode"></param>
        /// <param name="Pro_type_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int ProductCount_Other(string procode, string Measure_id)
        {
            return db_ProductRepository.ProductCount_Other(procode, Measure_id);
        }

        /// <summary>
        /// 添加产品基础信息
        /// </summary>
        /// <param name="db_ProductAddDto"></param>
        /// <returns></returns>
        public async Task<string> ProductAddAsync(Db_ProductAddDto db_ProductAddDto)
        {
            Db_Product db_Product = mapper.Map<Db_Product>(db_ProductAddDto);
            return await db_ProductRepository.ProductAddAsync(db_Product);
        }

        /// <summary>
        /// 条件查询产品总数
        /// </summary>
        /// <param name="proName"></param>
        /// <param name="typeCode"></param>
        /// <returns></returns>
        public int ProductCount(string proName, string typeCode)
        {
            return db_ProductRepository.ProductCount(proName,typeCode);
        }



        /// <summary>
        /// 逻辑删除产品信息
        /// </summary>
        /// <param name="db_ProductDelDto"></param>
        /// <returns></returns>
        public async Task<int> ProductDelAsync(Db_ProductDelDto db_ProductDelDto)
        {
            Db_Product db_Product = mapper.Map<Db_Product>(db_ProductDelDto);
            return await db_ProductRepository.ProductDelAsync(db_Product);
        }

        /// <summary>
        /// 修改产品信息
        /// </summary>
        /// <param name="db_ProductUpdateDto"></param>
        /// <returns></returns>
        public async Task<int> ProductUpdateAsync(Db_ProductUpdateDto db_ProductUpdateDto)
        {
            Db_Product db_Product = mapper.Map<Db_Product>(db_ProductUpdateDto);
            return await db_ProductRepository.ProductUpdateAsync(db_Product);
        }
    }
}
